<?php

/**
 * Description of uniqueEmailValidator
 *
 * @author Ho Huu Tai <hohuutai.uns@gmail.com>
 */
class uniqueEmailValidator extends CValidator
{
    public $message;
    
    public function validateAttribute($object, $attribute)
    {
        $value = $object->$attribute;
        $isExistEmail = User::model()->exists('email=:email', array(':email'=>$value));
        if($isExistEmail)
        {
            $message=$this->message!==null?$this->message:Yii::t('lode','{attribute} "{value}" has already been taken.');
            $this->addError($object,$attribute,$message,array('{value}'=>$value));
        }
    }
    
    public function clientValidateAttribute($object, $attribute)
    {
       
    }
}

?>
